package com.cloud.adrian.novel.common.json.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * 用户名序列化工具（用于脱敏：用户密码等不应该展示）
 * @Author: xiangguiliang
 * @since: 2024/05/03
 */
public class UsernameSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(String s, JsonGenerator jsonGenerator,
                          SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeString(s.substring(0,3) + "****" + s.substring(7));
    }
}
